import { Provide, Scope, ScopeEnum } from '@midwayjs/core'
import { InjectEntityModel } from '@midwayjs/typeorm'
import { Repository } from 'typeorm'

import { SysConfigEntity } from '@/entity'

@Provide()
@Scope(ScopeEnum.Singleton)
export class ConfigService {
  @InjectEntityModel(SysConfigEntity)
  configModel: Repository<SysConfigEntity>

  async isSoloLogin() {
    const config = await this.configModel.findOne({
      where: { configKey: 'sys.base.soloLogin' }
    })

    return config.configValue === '0'
  }

  async isCaptchaCaseSensitive() {
    const config = await this.configModel.findOne({
      where: { configKey: 'sys.base.captchaCaseSensitive' }
    })

    return config.configValue === '0'
  }
}
